package com.itxiao.controller;

import com.itxiao.config.SystemConfig;
import com.itxiao.entity.SysUser;
import com.itxiao.pojo.bo.Page;
import com.itxiao.pojo.vo.R;
import com.itxiao.service.SysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Collections;
import java.util.List;


/**
 * (SysUser)表控制层
 *
 * @author makejava
 * @since 2025-09-17 15:07:29
 */
@RestController
@RequestMapping("admin/api/v1/sys-user")
@Api(tags = "系统用户模块")
@CrossOrigin
public class SysUserController {
    /**
     * 服务对象
     */
    @Resource
    private SysUserService sysUserService;


    @ApiOperation("分页查询")
    @PostMapping("/query")
    public R queryList(@RequestBody Page page) {
        return sysUserService.queryList(page);
    }

    @ApiOperation("添")
    @PostMapping("/add")
    public R add(@RequestBody SysUser sysUser) {
        return sysUserService.add(sysUser);
    }

    @ApiOperation("修改")
    @PutMapping("/update")
    public R update(@RequestBody SysUser sysUser) {
        return sysUserService.updateInfo(sysUser);
    }

    @ApiOperation("删除")
    @DeleteMapping("/delete")
    public R deleteBatch(@RequestBody List<Integer> ids) {
        return sysUserService.del(ids);
    }

    @ApiOperation("单个删除")
    @DeleteMapping("/delete/{id}")
    public R deleteById(@PathVariable Integer id) {
        return sysUserService.del(Collections.singletonList(id));
    }
    @ApiOperation("得到登录用户信息")
    @GetMapping("/get-info")
    public R getUserInfo(HttpServletRequest request) {
        return sysUserService.getUserInfo(request.getHeader(SystemConfig.HEADER_TOKEN));
    }
}

